﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 内容分页辅助类
//最后修改: 2010-11-16
using System;
using System.Collections;
using System.Text;
using System.Text.RegularExpressions;
namespace TRPOP.CMS.Template
{
    /// <summary>
    /// 内容分页辅助类
    /// </summary>
    public class ContentListPage
    {

        #region 分页辅助方法

        /// <summary>
        /// 根据 内容分页生成器 类型 生成分页导航HTML 【为了模板引擎使用】
        /// </summary>
        /// <param name="strPageingType"></param>
        /// <param name="intIndexPage">从1开始</param>
        /// <param name="intPageCount"></param>
        /// <param name="strPagename">文件名，不带后缀</param>
        /// <param name="strPageExtName">文件后缀名 .html</param>
        /// <returns></returns>
        public static string GetContentPaging(string strPageingType, int intIndexPage, int intPageCount, string strPagename, string strPageExtName)
        {
            string strReturn = string.Empty;
            switch (strPageingType)
            {
                default:
                    string strPre = "<span><a href='{0}' >{1}</a></span>";
                    string strNext = "<span><a href='{0}' >{1}</a></span>";
                    string strIndex = "<a href='{0}'>{1}</a>&nbsp;";
                    bool blnPre = intIndexPage > 1;//上一页 是否显示
                    bool blnNext = intIndexPage < intPageCount;//下一页 是否显示
                    for (int i = 1; i <= intPageCount; i++)
                    {
                        if (i == intIndexPage)
                            strReturn += string.Format("<b>[{0}]</b>&nbsp;", intIndexPage);
                        else
                        {
                            strReturn += string.Format(strIndex,
                                                       strPagename + GetPageNameNum(i) + strPageExtName,
                                                       i.ToString()
                                                       );
                        }
                    }
                    strPre = blnPre ? string.Format(strPre,
                                                     strPagename + GetPageNameNum(intIndexPage - 1) + strPageExtName,
                                                    "上一页"
                                                    )
                                     : "";
                    strNext = blnNext ? string.Format(strNext,
                                                      strPagename + GetPageNameNum(intIndexPage + 1) + strPageExtName,
                                                      "下一页"
                                                      )
                                      : "";
                    strReturn = string.Format("<div class=\"pageingClass\">&nbsp;&nbsp;{0}" + strReturn + "&nbsp;&nbsp;{1}</div>",
                                               strPre,
                                               strNext
                                               );
                    break;
            }
            return strReturn;
        }

        /// <summary>
        /// 根据当前编号，获取已区分内容分页所增加的额外的字符
        /// 例如 123.html 123_1.html 123_2.html
        /// </summary>
        /// <param name="intPageIndex">页面编号从1开始</param>
        /// <returns></returns>
        public static string GetPageNameNum(int intPageIndex)
        {
            return intPageIndex <= 1 ? "" : ("_" + (intPageIndex - 1).ToString());
        }

        #endregion
    }
}
